package com.lmscn.lms.api.model;

import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;

import java.util.List;

/**
 * Created by Czl on 2015/7/21.
 */
@SuppressWarnings("serial")
public class Student extends Model<Student> {

    public static final Student dao = new Student();

    /**
     * 分页查询学员
     * @param pageNumber
     * @param pageSize
     * @return
     */
    public Page<Student> paginate(int pageNumber, int pageSize) {
        return paginate(pageNumber, pageSize, "select * ", " from t_student order by id asc");
    }

    public Student findByUserId(Long userId){
        String sql = "select * from t_student where user_id=?";
        return findFirst(sql, userId);
    }
    
    public Student findByUserIdAndGroup(Long userId, String group){
        String sql = "select * from t_student where user_id=? and study_group=?";
        return findFirst(sql, userId, group);
    }

    /**
     * 用户表一对一
     * @return
     */
    public SysUser getUser(){
        return SysUser.dao.findById(get("user_id"));
    }

    /**
     * 组织一对一
     * @return
     */
    public Org getOrg(){
        return Org.dao.findById(get("org_id"));
    }

    /**
     * 查询所有
     * @return
     */
    public List<Student> findAll(){
        return dao.find("select t.* from t_student t");
    }

}
